package kr.pe.mkseo.data.persistence;

import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import kr.pe.mkseo.data.Pair;

import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;

/**
 * Package that supports reads/writes to and from CSV files.
 * 
 * @author mkseo
 */
public class CsvDatabase {
	public CsvDatabase() {
	}
	
	public void WriteToFile(Object obj) {
		CsvDataFile dataFile = obj.getClass().getAnnotation(CsvDataFile.class);
		GetCsvDataFields(obj, fieldsToWrite);
	}

	private void GetCsvDataFields(Object obj) {
		List<Pair<Integer, Field>> fieldsToWrite = Lists.newArrayList();
		for (Field f: obj.getClass().getFields()) {
			CsvDataField dataField = f.getAnnotation(CsvDataField.class);
			if (dataField != null) {
				fieldsToWrite.add(Pair.NewPair(dataField.Order(), f));
			}
		}
		Collections.sort(fieldsToWrite,
				new Comparator<Pair<Integer, Field>>() {
					@Override
					public int compare(Pair<Integer, Field> o1, Pair<Integer, Field> o2) {
						return o2.GetFirst() - o1.GetFirst();
					}
				});
		return Lists.transform(fieldsToWrite, 
				new Function(Pair<Integer, Field> input) {
			return 
		}
	}
}
